/**
 * @file 账单管理 常量列表
 * @author lishaohai
 */

import {handleGetBillStatusTextByStatus} from '@/views/bill/filters-bill';

//  账单状态
export const BILL_STATUS_REPAYMENT = 1; // 还款中
export const BILL_STATUS_SETTLED = 2; // 已结清
export const BILL_STATUS_PAST_DUE = 3; // 已逾期
//  账单状态 对应的文案
export const BILL_STATUS_TEXT_REPAYMENT = '还款中'; // 还款中
export const BILL_STATUS_TEXT_SETTLED = '已结清'; // 已结清
export const BILL_STATUS_TEXT_PAST_DUE = '已逾期'; // 已逾期

/**
 * @returns 返回账单状态options
 */
export function getBillStatusOptions() {
    return [
        {
            label: BILL_STATUS_TEXT_REPAYMENT,
            value: BILL_STATUS_REPAYMENT
        },
        {
            label: BILL_STATUS_TEXT_SETTLED,
            value: BILL_STATUS_SETTLED
        },
        {
            label: BILL_STATUS_TEXT_PAST_DUE,
            value: BILL_STATUS_PAST_DUE
        }
    ];
}

// 补全默认的还款金额
export function getDefaultCashs() {
    return [
        {_id: BILL_STATUS_REPAYMENT, value: 0, count: 0, title: handleGetBillStatusTextByStatus(BILL_STATUS_REPAYMENT)},
        {_id: BILL_STATUS_SETTLED, value: 0, count: 0, title: handleGetBillStatusTextByStatus(BILL_STATUS_SETTLED)},
        {_id: BILL_STATUS_PAST_DUE, value: 0, count: 0, title: handleGetBillStatusTextByStatus(BILL_STATUS_PAST_DUE)}
    ];
}

// 日期组件默认的选项
export function getDefaultPickerOptions() {
    return {
        shortcuts: [
            {
                text: '最近一周',
                onClick(picker) {
                    const end = new Date();
                    const start = new Date();
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                    picker.$emit('pick', [start, end]);
                }
            },
            {
                text: '最近一个月',
                onClick(picker) {
                    const end = new Date();
                    const start = new Date();
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                    picker.$emit('pick', [start, end]);
                }
            },
            {
                text: '最近三个月',
                onClick(picker) {
                    const end = new Date();
                    const start = new Date();
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                    picker.$emit('pick', [start, end]);
                }
            }
        ]
    };
}

export function handleGetColumns() {
    const column = {
        from_time: '借款时间',
        platform: '借款平台',
        name: '账单名称',
        'current.status': '账单状态',
        create_date: '创建时间',
        'current.date': '还款日期',
        'current.cash': '本期待还',
        'current.stage': '当前期数/总期数',
        total: '借款金额',
        total_all: '合计需还',
        rate: '综合年化费率',
        bank: '还款银行',
        remark: '备注',
        operation: '操作'
    };
    return Object.keys(column).map(item => ({label: column[item], value: item}));
}
